#!/bin/bash

setup_os_config()
{
    echo >> /etc/motd
    echo 'You can configure this system or install to disk using "sudo os-config"' >> /etc/motd
    mkdir -p /usr/local/bin
    cat > /usr/local/bin/os-config << "EOF"
#!/bin/bash
exec /usr/libexec/k3os/k3os-config
EOF
    chmod +x /usr/local/bin/os-config
}

K3OS_ISO=$(blkid -L K3OS || true)
if [ -n "$K3OS_ISO" ]; then
    mount -t iso9660 -o ro $(blkid -L K3OS) /.base
else
    for i in $(lsblk -o NAME,TYPE -n | grep -w disk | awk '{print $1}'); do
        if mount -t iso9660 /dev/$i /.base; then
            break
        fi
    done
fi

setup_kernel

# no passwords in live mode
passwd -d rancher >/dev/null 2>&1

setup_os_config
